<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8"
         contentType="text/html;charset=utf-8" %>
<%@ include file="/common/taglibs.jsp" %>
<head>
    <title>商品编辑</title>
</head>
<body>
<div id="wrapper">
    <c:set var="left">product</c:set>
    <%@ include file="/include/left/operation.jsp" %>

    <div id="page-wrapper" class="gray-bg">

        <div class="row wrapper border-bottom white-bg page-heading">
            <div class="col-lg-10">
                <h2>商品编辑</h2>
                <ol class="breadcrumb">
                    <li>
                        <a href="${ctx}/product/">运营管理</a>
                    </li>
                    <li>
                        <a>商品管理</a>
                    </li>
                    <li class="active">
                        <strong>商品编辑</strong>
                    </li>
                </ol>
            </div>
        </div>

        <s:action name="product!view" var="view" executeResult="false"/>

        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content">
                            <s:form id="productFrom" action="product!update.action" class="form-horizontal"
                                    method="post" namespace="">
                                <input type="hidden" name="redirect" value="/product/"/>
                                <input type="hidden" name="id" value="${view.product.id}"/>

                                <div class="form-group"><label class="col-sm-2 control-label">商品名称</label>
                                    <div class="col-sm-6">
                                        <input type="text" name="product.name" value="${view.product.name}"
                                               class="form-control  validate[required]" placeholder="请输入商品名称">
                                    </div>
                                </div>

                                <div class="form-group"><label class="col-sm-2 control-label">分类</label>
                                    <div class="col-sm-6">
                                            <%--<s:action name="product-category!list" var="productCategoryList" executeResult="false">--%>
                                            <%--<s:param name="query.enabled">true</s:param>--%>
                                            <%--<s:param name="query.order">addTime</s:param>--%>
                                            <%--<s:param name="query.desc">true</s:param>--%>
                                            <%--</s:action>--%>
                                            <%--<select name="product.productCategory.id"  class="form-control validate[required]">--%>
                                            <%--<option value="">请选择所属分类</option>--%>
                                            <%--<s:iterator value="%{#productCategoryList.productCategories}" var="productCategory">--%>
                                            <%--<option value="${productCategory.id}" <c:if test="${productCategory.id==view.product.productCategory.id}">selected</c:if>>${productCategory.name}</option>--%>
                                            <%--</s:iterator>--%>
                                            <%--</select>--%>

                                        <input type="hidden" name="product.productCategory.id" value="<c:if test="${param.productCategoryId==null || param.productCategoryId==''}">${view.product.productCategory.id}</c:if><c:if test="${param.productCategoryId!=null && param.productCategoryId!=''}">${param.productCategoryId}</c:if>">
                                        <input type="text" class="form-control validate[required]" readonly placeholder="请选择商品分类" value="<c:if test="${param.productCategoryName==null || param.productCategoryName==''}">${view.product.productCategory.name}</c:if><c:if test="${param.productCategoryName!=null && param.productCategoryName!=''}">${param.productCategoryName}</c:if>">
                                                <a href="${ctx}/productCategory/choose.jsp?old=${ctx}/product/edit/${view.product.id}" class="btn btn-xs btn-success">选择</a>
                                    </div>
                                </div>

                                <div class="form-group"><label class="col-sm-2 control-label">商品价格</label>
                                    <div class="col-sm-6">
                                        <input type="text" name="product.price" value="${view.product.price}"
                                               class="form-control  validate[required,min[0],custom[number]]"
                                               placeholder="请输入商品价格">
                                    </div>
                                </div>

                                <div class="form-group"><label class="col-sm-2 control-label">商品成本价</label>
                                    <div class="col-sm-6">
                                        <input type="text" name="product.costPrice" value="${view.product.costPrice}"
                                               class="form-control  validate[required,min[0],custom[number]]"
                                               placeholder="请输入商品成本价">
                                    </div>
                                </div>

                                <div class="form-group"><label class="col-sm-2 control-label">商品市场价</label>
                                    <div class="col-sm-6">
                                        <input type="text" name="product.marketPrice"
                                               value="${view.product.marketPrice}"
                                               class="form-control  validate[required,min[0],custom[number]]"
                                               placeholder="请输入商品市场价">
                                    </div>
                                </div>

                                <div class="form-group"><label class="col-sm-2 control-label">商品描述</label>
                                    <div class="col-sm-6">
                                        <textarea name="product.description" class="form-control  validate[required]"
                                                  placeholder="请输入商品描述">${view.product.description}</textarea>
                                    </div>
                                </div>


                                <div class="form-group"><label class="col-sm-2 control-label">商品简介</label>
                                    <div class="col-sm-10">
                                        <textarea class="form-control" name="product.content"
                                                  id="content">${view.product.content}</textarea>
                                    </div>
                                </div>

                                <div class="form-group"><label class="col-sm-2 control-label">主图片</label>
                                    <div class="col-sm-10">
                                        <div class="m-upimgview">
                                            <img id="preview-img" height="200px;" width="200px;"
                                                 src="${view.product.img}!small.jpg">
                                            <input id="upimg" type="hidden" name="product.img"
                                                   value="${view.product.img}">

                                            <input id="fileupload" name="file" class="hidden" type="file"/>

                                            <div class="progress progress-mini">
                                                <div id="progress" style="" class="progress-bar"></div>
                                            </div>
                                        </div>

                                        <a class="btn btn-primary" href="javascript:;"
                                           onclick="fileUp('preview-img','upimg','progress','fileupload');">选择一个文件</a>
                                    </div>
                                </div>

                                <div class="form-group"><label class="col-sm-2 control-label">多图片</label>
                                    <div class="col-sm-10">
                                        <div class="m-upimgviewgroup" id="upimgviewgroup">
                                                <%--图片 图片逗号隔开--%>
                                            <c:set var="imgs" value="${fn:split(view.product.imgs, ',')}"></c:set>
                                            <c:if test="${fn:length(imgs)>0}">
                                                <c:forEach var="im" items="${imgs}" varStatus="status" end="10">
                                                    <span class="img"><i onclick="DelImg(this)">x</i><img bigimg="${im}"
                                                                                                          src="${im}!small.jpg"></span>
                                                </c:forEach>
                                            </c:if>
                                                <%--图片 end--%>
                                            <a class="btn-addimgs" href="javascript:;"
                                               onclick="fileUpGroup('upimgviewgroup','upimgobj','fileuploadgrpups');">
                                                <i>+</i>
                                                <span>选择一个图片</span>
                                                <em style=""></em>
                                            </a>
                                            <input id="fileuploadgrpups" name="file" class="hidden" type="file"/>
                                            <input id="upimgobj" type="hidden" name="product.imgs"
                                                   value="${view.product.imgs}">
                                        </div>
                                    </div>
                                </div>


                                <div class="hr-line-dashed"></div>
                                <div class="form-group">
                                    <div class="col-sm-4 col-sm-offset-2">
                                        <button class="btn btn-white" type="button"
                                                onclick="javascript:history.back(-1);">取消
                                        </button>
                                        <button class="btn btn-primary" id="submitButton" type="submit"
                                                data-loading-text="提交中...">发布
                                        </button>
                                    </div>
                                </div>
                            </s:form>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <%@ include file="/common/footer.jsp" %>
        <%--<a target="_blank" src="http://v.youku.com/v_show/id_XMzA0NTc3NzQ1Ng==.html?spm=a2hww.20023042.m_223465.5~5~5~5~5~5~A">事情</a>--%>

    </div>

</div>

<%@ include file="/common/scripts.jsp" %>
<%@ include file="/common/validate.jsp" %>
<%@ include file="/common/script/umeditor.jsp" %>
<%@ include file="/common/script/fileupload.jsp" %>


<script>
    $('#productFrom').validationEngine({
        promptPosition: 'topLeft',
        onValidationComplete: function (form, status) {
            if (status) {//当所有验证通过后再执行
                submitForm();
            }
        }
    });

    getUMEditor('content');

    function submitForm() {
        var _content = $('#content').val();
        if (_content == null || _content == '') {
            layer.msg('请输入有效正文内容');
        } else {
            $('#submitButton').button('loading')
            $('#productFrom').submit();
        }


    }
</script>

</body>

